<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8" />
    <title>登录</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black" />
    <meta name="format-detection" content="telephone=no">
    <meta name="renderer" content="webkit" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="renderer" content="webkit|ie-comp|ie-stand" />
    <link rel="shortcut icon" href="/favicon.ico" type="/image/x-icon">
    <link rel="apple-touch-icon-precomposed" href="">
    <link rel="stylesheet" href="../source/src/css/main.css?v=1209"/>
    <script src="../source/src/js/common.js"></script>

</head>
<body>
    <!-- 登录 -->
    <img src="../source/img/login/login_bg.jpg" alt="login_bg.jpg" class="login-bg">
    <div class="login pubForm-box">
        <div class="hd">
            <div class="logo">
                <img src="../source/img/public/logo.png" alt="logo.png">
            </div>
            <div class="company_name">
                <img src="../source/img/public/company_name.png" alt="company_name.png">
            </div>
        </div>
        <div class="bd">
            <ul>
                <li class="clearfix">
                    <div class="label fl">
                        用户名：
                    </div>
                    <div class="v fl">
                        <input type="text" name="" id="username" class="inp"/>
                    </div>
                </li>
                <li class="pwd-box clearfix">
                    <div class="label fl">
                        密　码：
                    </div>
                    <div class="v fl">
                        <input type="password" name="" id="password" class="inp"/>
                    </div>
                </li>
                <li class="error-tip animated">

                </li>
            </ul>
            <div class="btn-box">
                <input type="submit" value="登 录" id="login-btn" class="login-btn">
            </div>
        </div>
    </div>
    <!-- /登录 -->

    <script src="../source/plugin/zepto.min.js"></script>
    <script src="../source/src/js/common.js"></script>
    <script>
        function checkLogin(username,pwd){
            var  username=username,
                 pwd=pwd,
                 errorTxt='';
            if ($.trim(username)=="") {
                errorTxt="请输入用户名！";
            }else if($.trim(pwd)==""){
                errorTxt="请输入密码！";
            }
            return errorTxt !="" ? errorTxt : true;
        }

        $(function(){
            $('#login-btn').on('click',function(){
                var username=$('#username').val() || "",
                    pwd=$('#password').val() || "",
                    errorMsg = checkLogin(username,pwd);
                if(errorMsg===true){
                    $('.error-tip').html("").hide();
                    var json = {
                        "username":username,
                        "pwd":pwd,
                        "account":user.account,
                        "key":user.key,
                    };
                    $.ajax({
                        url:apiUrl+'/ChkLogin',
                        type:'GET',
                        data:{"json":JSON.stringify(json)},
//                      dataType :'jsonp',
                        success:function(datas){
                            if(datas.Success===true){
                                setCookie('CustCode',datas.CustCode,720);
                                setCookie('username',encodeURIComponent(username),720);
                                setCookie('CustName',encodeURIComponent(datas.CustName),720);
                                setCookie('EmpCode',datas.EmpCode,720);
                                setCookie('EmpName',encodeURIComponent(datas.EmpName),720);
                                setCookie('Type',datas.Type,720);
                                setCookie('phoneNum',datas.MobiePhone,720);
                                location.href='../index.html';
                            }else{
                                $('.error-tip').html("用户名或密码错误").show().addClass('shake').one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', function(){
                                    $(this).removeClass('shake');
                                });
                            }
                        },
                        error:function(datas){
                            if(datas.Msg){
                                $('.error-tip').html(datas.Msg).show().addClass('shake').one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', function(){
                                    $(this).removeClass('shake');
                                });
                            }else{
                                show_error_tip();
                            }
                        }
                    });
                }else{//验证出错
                    $('.error-tip').html(errorMsg).show().addClass('shake').one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', function(){
                        $(this).removeClass('shake');
                    });
                }
            })
        })
    </script>
</body>
</html>